/*angular.module('logincat', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/', {templateUrl: '/static/views/login.html',   controller: LoginCtrl}).
      otherwise({redirectTo: '/'});}
      $httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val();
]);*/

angular.module('logincat', []).
	config(function($routeProvider, $httpProvider) {
		//$routeProvider.when('/', {templateUrl: '/static/views/login.html',   controller: LoginCtrl});
		$routeProvider.when('/', {templateUrl: '/static/views/home.html', controller: HomeCtrl});
		$routeProvider.otherwise({redirectTo: '/'});
		/*$http({
			method: 'POST',
			url: '/',
			data: {'X-CSRFToken', 'CSRFToken'},
			headers: {'Content-Type': 'application/x-www-form-urlencoded'}
		});*/
		$httpProvider.defaults.headers.common['CSRF-TOKEN'] = "CSRFToken";
	});

function LoginCtrl($scope, $routeParams, $http) {
};

function HomeCtrl($scope, $routeParams, $http) {

};

function loginCtrl($scope, $http) {
	$scope.master= {};

	$scope.update = function(user) {
		$scope.master = angular.copy(user);
	};

	$scope.reset = function() {
		$scope.user = angular.copy($scope.master);
	};

	$scope.loginSubmit = function loginSubmit() {
		//$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
		//$http.defaults.headers.post['X-XSRF-TOKEN'] = 'CSRFToken';

		$http.post("/login/login", JSON.stringify($scope.master))
		.success(function(data) {
			//alert(data);
			//alert(status);
			//alert(headers);
			//alert(data.success);
			alert(data.username);
			//alert({"username" : "wyunchi"}.username);
			$scope.master.username = "success";
			$location("http://baidu.com");
		}).error(function(data) {
			alert("error");
			$scope.master.username = "error";
		});

	}

	$scope.reset();
}